package com.xmut.mall.coupon.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xmut.mall.coupon.enums.PromotionsStatusEnum;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * 获取券活动的详情
 */
@Data
public class CouponActivityDetailVo {
    private Long id;

    private String promotionName;

    private String couponActivityType;

    private String activityScopeInfo;

    private String activityScope;

    private String promotionStatus;

    private List<CouponActivityItemsVo> couponActivityItems;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;


    /**
     * @return 满减活动的状态
     * @see PromotionsStatusEnum
     */
    public String getPromotionStatus() {
        if (endTime == null) {
            return startTime != null ? PromotionsStatusEnum.START.name() : PromotionsStatusEnum.CLOSE.name();
        }
        Date now = new Date();
        if (now.before(startTime)) {
            return PromotionsStatusEnum.NEW.name();
        } else if (endTime.before(now)) {
            return PromotionsStatusEnum.END.name();
        } else if (now.before(endTime)) {
            return PromotionsStatusEnum.START.name();
        }
        return PromotionsStatusEnum.CLOSE.name();
    }
}
